import './index.css';
import * as React from 'react';
import './utils/leancloud-helper';
import * as ReactDOM from 'react-dom/client';
import { createHashRouter, createBrowserRouter, RouterProvider } from 'react-router-dom';


const Home = React.lazy(() => import('./pages/home'));
const Admin = React.lazy(() => import('./pages/admin'));
const AdminHome = React.lazy(() => import('./pages/admin/home'));
const User = React.lazy(() => import('./pages/admin/user'));
const Ban = React.lazy(() => import('./pages/admin/ban'));

console.log(import.meta.env);

const router = createBrowserRouter([
  {
    path: '/',
    element: <Home />
  },
  {
    path: 'admin',
    element: <Admin />,
    children: [
      {
        path: '',
        element: <AdminHome />
      },
      {
        path: 'user',
        element: <User />
      },
      {
        path: 'ban',
        element: <Ban />
      }
    ]
  }
],{
  basename: import.meta.env.BASE_URL
});


const rootEl = document.querySelector('#root');
ReactDOM.createRoot(rootEl).render(
  // 如果路由开启了懒加载 这里一定要加 React.Suspense包裹
  <React.Suspense>
    <RouterProvider router={router} />
  </React.Suspense>
);
